<?php
class IndexControl extends Control {
	public function index(){
		
		$id=isset($_GET['id'])?$_GET['id']:'';
		$pageNo=isset($_GET['pageNo'])?$_GET['pageNo']:1;
		if(!$this->view->isCached('index.tpl',$id.'|'.$pageNo)){
			//公共部分
			$str=file_get_contents(CONFIG_DIR.'/public.conf');
			eval($str);
			//分类列表
			$cate=new CategoryModel();
			$cateData=$cate->fetchAll();
			$cateData=pidsort($cateData);
			
			//热销榜
			$goods=new GoodsModel();
			$hotgoodsData=$goods->hotgoods();
			
			
			//分页及商品数据列表
			$page=new Page('goods');
			$page->wherepid=$id;//一级分类
			$page->pageSize=9;
			$page->pageNo=$pageNo;
			$goodslistData=$page->init();
			$pagestr=$page->getPager();
			
			$this->view->assign('cateData',$cateData);
			$this->view->assign('cateName',$cateName);
			$this->view->assign('hotgoodsData',$hotgoodsData);
			$this->view->assign('goodslistData',$goodslistData);
			$this->view->assign('pagestr',$pagestr);
		}
		
		$this->view->display('index.tpl',$id.'|'.$pageNo);
		
	}
	public function ajaxsort(){
		$sort=isset($_POST['sort'])?$_POST['sort']:(isset($_SESSION['ajaxsort'])?$_SESSION['ajaxsort']:'id');
		$order=isset($_POST['order'])?$_POST['order']:(isset($_SESSION['ajaxorder'])?$_SESSION['ajaxorder']:'desc');
		$pageNo=isset($_GET['pageNo'])?$_GET['pageNo']:1;
		
		$page=new Page('goods');
		$page->sort=$sort;
		$page->order=$order;
		
		$page->pageSize=9;
		$goodslistData=$page->init();
		
		echo json_encode($goodslistData);
	}
	
	/**
	 * 进入物品详细信息
	 *
	 */
	public function goods(){
		$id=$_GET['id'];
		if(!$this->view->isCached('goods.tpl',$id)){
			//公共部分
			$str=file_get_contents(CONFIG_DIR.'/public.conf');
			eval($str);
			
			$goods=new GoodsModel();
			$goodsData=$goods->selGoods($id);
			$this->view->assign('goodsData',$goodsData);
			
			$goodscomment=new GoodscommentModel();
			$goodscommentData=$goodscomment->fetchcomment($id);
			$this->view->assign('goodscommentData',$goodscommentData);
		
			$goodid=$goodsData['id'];
			$goodscate=new GoodsCateModel();
			$goodscateData=$goodscate->where($goodid);
			$this->view->assign('goodscateData',$goodscateData);
		}
		
		
		$this->view->display('goods.tpl',$id);
		
	}
	
	public function cate(){
		$id=$_GET['id'];
		if(!$this->view->isCached('index.tpl',$id)){
			//公共部分
			$str=file_get_contents(CONFIG_DIR.'/public.conf');
			eval($str);
			//分类列表
			$cate=new CategoryModel();
			$cateData=$cate->fetchAll();
			$cateData=pidsort($cateData);
			
			//热销榜
			$goods=new GoodsModel();
			$hotgoodsData=$goods->hotgoods();
			
			$page=new PageB('goods');
			$page->pid=$id;
			$page->pageSize=9;
			$goodslistData=$page->init();
			$pagestr=$page->getPager();
			
			$this->view->assign('cateData',$cateData);
			$this->view->assign('hotgoodsData',$hotgoodsData);
			$this->view->assign('goodslistData',$goodslistData);
			$this->view->assign('pagestr',$pagestr);
		}
		$this->view->display('index.tpl',$id);
		
	}
	
	public function message(){
		if(!$this->view->isCached('goods.tpl')){
			//公共部分
			$str=file_get_contents(CONFIG_DIR.'/public.conf');
			eval($str);
			$message=new MessageModel();
			$messageData=$message->fetchAll();
			$this->view->assign('messageData',$messageData);
		}
		$this->view->display('message.tpl');
		
	}
	
}
?>